Skip to content

Convert "method has return statement; needs result type" to new error format with MissingReturnTypeWithReturnStatement #3094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

TheReturningVoid
Copy link
Contributor

Convert "method has return statement; needs result type" to new error format with MissingReturnTypeWithReturnStatement

… format with MissingReturnTypeWithReturnStatement
Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Commit Messages

We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).

Please stick to these guidelines for commit messages:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Added" instead of "Add")
  7. Wrap the body at 80 characters
  8. Use the body to explain what and why vs. how

adapted from https://chris.beams.io/posts/git-commit

Have an awesome day! ☀️

@smarter
Copy link
Member

smarter commented Sep 13, 2017

@allanrenucci: could you review this PR please?

@allanrenucci allanrenucci self-requested a review September 13, 2017 13:17
@allanrenucci allanrenucci self-assigned this Sep 13, 2017
val msg = hl"$method has a return statement; it needs a result type"
val explanation =
hl"""|If a method contains a ${"return"} statement, it must have a return
|type explicitly given to it. For example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...it must have an explicit result type. For example:

hl"""|If a method contains a ${"return"} statement, it must have a return
|type explicitly given to it. For example:
|
|${"def bad() = { return \"fail\" }"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would give a valid example instead:

def good: Int /* explicit result type */ = {
  return 1
}


val MissingReturnTypeWithReturnStatement(method) :: Nil = messages

assertEquals(method.name.toString, "bad")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name.show

""".stripMargin
}.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
val defn = ictx.definitions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

@TheReturningVoid
Copy link
Contributor Author

I've corrected the PR as per your review comments.

@@ -963,13 +963,9 @@ class ErrorMessagesTests extends ErrorMessagesTest {
|}
""".stripMargin
}.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defn was not used but I think you still need the implicit ctx. It is passed implicitly to the method show

assertMessageCount(1, messages)

val MissingReturnTypeWithReturnStatement(method) :: Nil = messages

assertEquals(method.name.toString, "bad")
assertEquals(method.show, "bad")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be method.name.show

@TheReturningVoid
Copy link
Contributor Author

Sorry, should have run the tests :P Should be all good now.

Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheReturningVoid Thank you for your contribution 🎉

LGTM. Just waiting for the CI to go green

@allanrenucci allanrenucci merged commit 51388eb into scala:master Sep 14, 2017
@TheReturningVoid TheReturningVoid deleted the 1589-message-missing-return-type-with-return-statement branch September 14, 2017 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants